#include "Container.h"
#include <gtest/gtest.h>

class ContainerTestEnvironment : public testing::Environment
{
    public:
        virtual void SetUp()
            {
                cout<<"Container test environment SetUp"<<endl;
            }
        virtual void TearDown()
            {
                cout<<"Container test environment TearDown"<<endl;
            }
};
TEST(ContainerConstructorTest, TestConstructor)
{

    Container container;
    //container::Container();
    EXPECT_EQ(0,container.get_size());
 //   container.~Container();
}

TEST(ContainerGet_sizeTest, TestGet_sizeEmpty)
{
    Container container;
    int size = container.get_size();
    EXPECT_EQ(0,size);
   // container.~Container();
}

TEST(ContainerGet_sizeTest, TestGet_sizePositive)
{
    Container container;
    const string str1("first");    
    container.add_item(str1);
    int size = container.get_size();
    EXPECT_EQ(1,size);
}

TEST(ContainerAdd_itemTest, TestAdd_itemPositiveCase1)
{
    const string str1("first");
    Container container;
    int k = container.add_item(str1);
    EXPECT_EQ(0,k);
}

TEST(ContainerAdd_itemTest, TestAdd_itemPositiveCase2)
{
    const string str1("first");
    const string str2("second");
    Container container;
    container.add_item(str1);
    int k = container.add_item(str2);
    EXPECT_EQ(1,k);
}

TEST(ContainerAdd_itemTest, TestAdd_itemNegativeCase)
{
    const string str1("first");
    Container container;
    container.add_item(str1);
    int k = container.add_item(str1);
    EXPECT_EQ(-1,k);
}

TEST(ContainerGet_itemTest, TestGet_itemOutOfRangeCase1)
{
    Container container;
    EXPECT_THROW(container.get_item(-1),IncompatibleContainerError);
}

TEST(ContainerGet_itemTest, TestGet_itemOutOfRangeCase2)
{
    const string str1("first");
    const string str2("second");
    Container container;
    container.add_item(str1);
    container.add_item(str2);
    EXPECT_THROW(container.get_item(100),IncompatibleContainerError);
}

TEST(ContainerGet_itemTest, TestGet_itemPositivecase)
{
    const string str1("first");
    const string str2("second");
    Container container;
    container.add_item(str1);
    container.add_item(str2);
    EXPECT_STREQ(str2.c_str(),container.get_item(1).c_str());  
}

TEST(ContainerRemoveTest,TestRemoveNegativeCase1)
{
    Container container;
    bool res=container.remove_item(-1);
    EXPECT_TRUE(!res);
} 

TEST(ContainerRemoveTest,TestRemoveNegativeCase2)
{
    const string str1("first");
    const string str2("second");
    Container container;
    container.add_item(str1);
    container.add_item(str2);
    bool res=container.remove_item(2);
    EXPECT_TRUE(!res);
} 

TEST(ContainerRemoveTest, TestRemovePositivecase1)
{
    const string str1("first");
    const string str2("second");
    Container container;
    container.add_item(str1);
    container.add_item(str2);
    bool res=container.remove_item(1);
    EXPECT_TRUE(res);	
}

TEST(ContainerRemoveTest, TestRemovePositivecase2)
{
    const string str1("first");
    const string str2("second");
    Container container;
    container.add_item(str1);
    container.add_item(str2);
    bool res=container.remove_item(0);
    EXPECT_TRUE(res);	
}


int main(int argc, char** argv)
{
    testing::AddGlobalTestEnvironment(new ContainerTestEnvironment);
    testing::InitGoogleTest(&argc , argv);
    return RUN_ALL_TESTS();
}
